package com.cskaoyan.controller.lz_controller;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.User;
import com.cskaoyan.bean.lzpackage.UserData;
import com.cskaoyan.bean.params.BaseParam;
import com.cskaoyan.lz_service.UserService;
import com.cskaoyan.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("admin/user")
public class AdminUserController {
    /*  */
    @Autowired
    UserMapper userMapper;
    @Autowired
    UserService userService;

    @RequestMapping("list")
    public BaseRespVo list(String username, BaseParam param, String mobile) {

        UserData userData = userService.query(param, username, mobile);
        return BaseRespVo.ok(userData);
    }

    @RequestMapping("update")
    public BaseRespVo update(@RequestBody User user) {
        //TODO:这里应该需要添加逻辑判断---数据库中的账号名和密码有重合的账号
        int user1 = userMapper.updateByPrimaryKeySelective(user);
        return BaseRespVo.ok(user1);
    }

    @RequestMapping("detail")
    public BaseRespVo detail(Integer id) {
        User user1 = userMapper.selectByPrimaryKey(id);
        return BaseRespVo.ok(user1);
    }
}
